package com.moore.controller;

import com.moore.bean.Community;
import com.moore.dto.ResponseData;
import com.moore.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

import static com.moore.utils.Logger.toLog;

@Controller
@RequestMapping("/community")
public class CommunityController {
    @Autowired
    private CommunityService communityService;

    @RequestMapping("/add")
    @ResponseBody
    public ResponseData addCommunity(@RequestBody Community community){
        toLog("正在添加小区"+community.getName());
        return communityService.addCommunity(community);
    }

    @RequestMapping("/get")
    @ResponseBody
    public ResponseData getCommunity(@RequestBody Community community, HttpServletRequest request){
        toLog("正在获取"+community.getArea()+"区域的小区");
        return communityService.getCommunity(community,request);
    }

    @RequestMapping("/update")
    @ResponseBody
    public ResponseData updateCommunity(@RequestBody Community community) {
        toLog("正在修改小区" + community.getName());
        return communityService.updateCommunity(community);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData deleteCommunity(@RequestBody List<Community> community) {
        toLog("正在删除小区");
        return communityService.deleteCommunity(community);
    }
}
